package com.example.tomcatdemo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import jakarta.servlet.http.HttpServletRequest; // 使用 jakarta 包

@RestController
public class TomcatController {

    @GetMapping("/server-info")
    public String getServerInfo(HttpServletRequest request) {
        StringBuilder info = new StringBuilder();
        info.append("<h2>Tomcat Server Info</h2>");
        info.append("<p>Server: ").append(request.getServletContext().getServerInfo()).append("</p>");
        info.append("<p>Context Path: ").append(request.getContextPath()).append("</p>");
        info.append("<p>Protocol: ").append(request.getProtocol()).append("</p>");
        info.append("<p>Local Port: ").append(request.getLocalPort()).append("</p>");
        info.append("<p>Thread Pool Size: ").append(Thread.activeCount()).append("</p>");
        return info.toString();
    }

    @GetMapping("/ping")
    public String ping() {
        return "Tomcat is running! Time: " + new java.util.Date();
    }
}
